#include <iostream>
#include <stdio.h>
//#include <math.h>
using namespace std;

int shu[100005];
int n,nn;
int maxl, maxr, maxv, nowl, nowr, now;
int left1, right1, tot1, tot2, tot;

int main()
{
    int i, j;
    while (1)
    {
	    scanf("%d", &nn);
	    if (!nn) break;
	    scanf("%d", &shu[1]);
	    scanf("%d", &shu[2]);
	    n = 2;
	    if (nn>2) 
     	{
          	scanf("%d", &shu[3]);
          	n = 3;
        }   	
	    for (i=4; i<=nn; ++i)
	    {
	    	scanf("%d", &j);
	    	if (shu[n]*j>0) shu[n]+=j;
	    	else shu[++n] = j;
	    }   	
    	
    
    	tot = -20000;
    	
    	for (j=1; j<n; ++j)
    	{
        	tot1 = -20000;
        	tot2 = -20000;
        	left1 = j;
        	right1 = j+1;
        	now = 0;
        	nowl = 0;
        	nowr = 0;
        	maxv = -20000;
        	for (i=1; i<=left1; ++i)
        	{
        	    now += shu[i];
        	    if (now > maxv)
        	    {
        	        maxv = now;
        	        maxl = nowl;
        	        maxr = i;
        	    }    
        	    if (now < 0) 
             	{
                    now = 0; 
                    nowl = i+1;
                }       	    
        	}   
        	tot1 = maxv;
        	
        	now = 0;
        	nowl = 0;
        	nowr = 0;
        	maxv = -20000;
        	for (i=right1; i<=n; ++i)
        	{
        	    now += shu[i];
        	    if (now > maxv)
        	    {
        	        maxv = now;
        	        maxl = nowl;
        	        maxr = i;
        	    }    
        	    if (now < 0) 
             	{
                    now = 0; 
                    nowl = i+1;
                }       	    
        	}   
        	tot2 = maxv;
        	tot1 += tot2;
        	if (tot < tot1 ) tot = tot1;
        	
        }   	
     	printf("%d\n", tot);	
    		
    	
	}    
   
    
    return 0;
}    


